package com.gitee.shigen.security.config;

import com.gitee.shigen.common.msg.Result;
import com.gitee.shigen.security.util.HttpServletResponseUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.security.web.access.AccessDeniedHandler;

/**
 * 各种handler的配置
 *
 * @author shigenfu
 * @date 2024/5/25 17:20
 */
@Configuration
public class SecurityHandlerConfig {

    @Bean
    public AccessDeniedHandler accessDeniedHandler() {
        return (request, response, accessDeniedException) -> {
            Result<String> result = new Result<>(HttpStatus.UNAUTHORIZED.value(), "权限不足", null);
            HttpServletResponseUtil.response(response, result);
        };
    }

}
